# import requests
#
# class HDFS:
#     def __init__(self, hdfs):
#         self.url_path = hdfs + "/webhdfs/v1"
#
#     def list(self, path):
#         response = requests.get(self.url_path + path + "?op=LISTSTATUS")
#         file_obj = response.json()
#         for f in file_obj['FileStatuses']['FileStatus']:
#             print("{}\t{}\t{}".format(f['owner'], f['group'],f['pathSuffix']))
#
#
# hdfs = HDFS("http://gesukj.com:50070")
# hdfs.list("/")

import hdfs

h = hdfs.Client("http://zhddong@zhddong-X550JX:50070")

def list(path):
    for f in h.list(path):
        print(f)

# create new file on hdfs
# h.write("/data/hello.txt", data="this is a text file")
# list("/data")


# read file from HDFS
with h.read("/data/Spark知道.md") as reader:
    data = reader.read()
    print(data)

# import snakebite
# from snakebite import client
#
# c = client.Client("zhddong@zhddong-X550JX", port=9000)
# for f in c.ls(["/", "/data"]):
#     print(f['path'])
#
# read data from data node (confirm that the datanodes can be accessed from local)
# for x in c.text(["/data/hello.txt"]):
#     print(x)

